package cn.icanci.test;

import cn.icanci.test.aspect.OutSide;
import cn.icanci.test.controller.HiController;
import cn.icanci.test.controller.WelcomeController;
import cn.icanci.test.entity.User;
import cn.icanci.test.introduction.LittleUniverse;
import cn.icanci.test.service.HelloService;
import cn.icanci.test.service.HiService;
import cn.icanci.test.service.WelcomeService;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 * TODO 管理bean的生命周期
 * 	BeanDefinition
 * @author icanci
 * @date Created in 2021/02/06 18:43
 * @version 1.0
 */
@Configuration
@ComponentScan("cn.icanci")
@SuppressWarnings("all")
@EnableAspectJAutoProxy
@Import(OutSide.class)
public class MainEntrance {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainEntrance.class);
		HiService hiService = (HiService)applicationContext.getBean("hiServiceImpl");
		hiService.sayHi();
		System.out.println("---------------------------");
		HelloService helloServiceImpl = (HelloService)applicationContext.getBean("helloServiceImpl");
		helloServiceImpl.sayHello();
		System.out.println("MainEntrance.main");
	}
    public static void main1(String[] args) throws Exception {
        String xml = "//Users/icanci/ideaProjects/Source/spring-framework-5.2.0.RELEASE/icanci-spring-demo/src/main/resources/spring-config.xml";
        ApplicationContext applicationContext = new FileSystemXmlApplicationContext(xml);
        WelcomeService welcomeService = (WelcomeService) applicationContext.getBean("welcomeService");
        welcomeService.sayHi();
        User user1 = (User) applicationContext.getBean("userFactoryBean");
        User user2 = (User) applicationContext.getBean("userFactoryBean");
        System.out.println(user1);
        System.out.println(user2);
    }

    public static void main2(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainEntrance.class);
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }
        WelcomeController welcome = (WelcomeController) applicationContext.getBean("welcomeController");

        welcome.sayHi();
        User user5 = (User) applicationContext.getBean("user5");
        System.out.println(user5);
    }

    public static void main3(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainEntrance.class);
        //		GirlFriend girlFriend = (GirlFriend) applicationContext.getBean("girlFriend");
//        HelloController helloController = (HelloController) applicationContext.getBean("helloController");
//        helloController.handleRequest();

        HiController hiController = (HiController) applicationContext.getBean("hiController");
		LittleUniverse littleUniverse = (LittleUniverse) hiController;
		littleUniverse.burningUp();
		//        hiController.handleRequest();
    }

}
